<template>
  <div class="news-list">
    <h3>全部资讯</h3>
    <template v-if="list">
      <div
        v-for="item in list"
        :key="item.id"
        class="news-list-item flex flex-jc-sp cursor-p"
        @click="go(item.id)"
      >
        <img
          style="width: 190px; height: 142px; margin-right: 18px"
          :src="item.thumb"
          alt=""
          srcset=""
        />
        <div style="width: 600px">
          <h4>{{ item.title }}</h4>
          <div class="time">{{ item.update_time }}</div>
          <div class="describe">
            {{ item.description }}
          </div>
        </div>
      </div>
    </template>

    <div class="flex flex-jc-c flex-ai-c">
      <el-pagination
        class="pagination"
        hide-on-single-page
        background
        layout="prev, pager, next"
        :total="total_count"
        @current-change="currentChange"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getApiBaseArticleList } from '@/api'
export default {
  data() {
    return {
      page_size: 10,
      page_number: 1,
      total_count: 0,
      list: null,
    }
  },
  created() {
    this.getArticleCateList()
  },
  methods: {
    currentChange(page) {
      this.page_number = page
      this.getArticleCateList()
    },
    getArticleCateList() {
      getApiBaseArticleList({
        page_size: this.page_size,
        page_number: this.page_number,
      }).then((res) => {
        if (res.code === 200) {
          const data = res.data.list
          this.list = data
          this.total_count = res.data.total_count
        }
      })
    },
    go(id) {
      this.$router.push(`detail/${id}`)
    },
  },
}
</script>

<style lang="less" scoped>
.news-list {
  .pagination {
    margin: 24px auto 136px;
  }
  h3 {
    font-size: 18px;
    color: #000;
    margin-bottom: 8px;
  }
  .news-list-item {
    padding: 20px 0;
    border-bottom: 1px dashed #d7d7d7;
    h4 {
      font-size: 18px;
      margin-bottom: 14px;
    }
    .time {
      font-size: 12px;
      color: #999;
      margin-bottom: 18px;
    }
    .describe {
      font-size: 12px;
      color: #999;
      line-height: 1.5;
    }
  }
}
</style>